#!/usr/bin/perl -w

############################################################
# A small little hook to parse the channel chat for URLs   #
# and make Tinyurls out of them. As requested by cshields. #
############################################################

use URI::Find::Rule;
use WWW::Shorten::TinyURL;
use WWW::Shorten 'TinyURL';

my $privmsg = 0;
my ($chan, $msg, $nick);
while(<>) {
	if(/^type\s+privmsg/) {
		$privmsg = 1;
	}
	elsif (/^to\s+(.+)/) {
		$chan = $1;
	}
	elsif (/^nick\s+(.+)/) {
		$nick = $1;
	}
	elsif (/^msg\s+(\S.+)/) {
		$msg = $1;
	}
}

my @urls = URI::Find::Rule->in($msg,1);
if(@urls){
	print "sendnext:\n";
	foreach $url (@urls){
		if(length($url->as_string) > 79){
			$short_url = makeashorterlink($url->as_string);	
			print "$nick\'s tiny URL is $short_url\n";
		}
	}
}
